package com.scs.application.modules.dept.controller;

import com.scs.application.core.mvc.controller.FlowController;
import com.scs.application.modules.dept.entity.OprtUse;
import com.scs.application.modules.dept.entity.Use;
import com.scs.application.modules.dept.entity.UseMerge;
import com.scs.application.modules.dept.service.UseMergeService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 */
@RestController
@RequestMapping("/dept/use_merge")
public class UseMergeController extends FlowController<UseMergeService, UseMerge> {

    @PostMapping("/saveByUseIds")
    public RestResult saveByUseIds(@Valid @RequestBody List<Use> entityList) {
        boolean isOk = service.saveByUseIds(entityList);
        if (!isOk) {
            return RestResult.error("数据保存失败");
        }
        return RestResult.ok("数据保存成功");
    }

    @PostMapping("/saveByOprtUseIds")
    public RestResult saveByOprtUseIds(@Valid @RequestBody List<OprtUse> entityList) {
        boolean isOk = service.saveByOprtUseIds(entityList);
        if (!isOk) {
            return RestResult.error("数据保存失败");
        }
        return RestResult.ok("数据保存成功");
    }


    @RequestMapping("/autoMergeOprtUseMain")
    synchronized public RestResult autoMergeOprtUseMain(String useMergeId) {
        return RestResult.ok(service.autoMergeOprtUseMain(useMergeId));
    }
}
